<template>
    <div>
        <table class="table" border="1">
            <tr>
                <td>项目名称</td>
                <td><input type="text" v-model="info.name"></td>
            </tr>
            <tr>
                <td>佣金</td>
                <td>
                    <input type="text" v-model="info.price">
                </td>
            </tr>
            <tr>
                <td>服务人数</td>
                <td>
                    <input type="text" v-model="info.num">
                </td>
            </tr>
            <tr>
                <td>服务时长</td>
                <td>
                    <input type="text" v-model="info.sc">
                </td>
            </tr>
            <tr>
                <td>项目说明</td>
                <td><input type="text" v-model="info.bz"></td>
            </tr>
            <tr>
                <td>状态</td>
                <td><input type="checkbox" v-model="info.stear">是否启用</td>
            </tr>
            <tr>
                <td><input type="button" value="添加" @click="add"></td>
            </tr>
        </table>

    </div>
</template>

<script setup lang="ts">
    import {ref} from 'vue';
    import axios from 'axios';
    import { useRouter } from 'vue-router';

    const router=useRouter();
    const info=ref({
  "id": 0,
  "name": "",
  "price": 0,
  "num": 0,
  "sc": 0,
  "stear": true,
  "bz": "",
  "lj": 0,
  "date": "2025-03-19T03:43:01.595Z"
})
const add=()=>{
    if(info.value.name==""){
        alert('项目名称不能为空');
        return;
    }
    if(info.value.price==0){
        alert('佣金不能为空');
        return;
    }
    if(info.value.num==0){
        alert('服务人数不能为空');
        return;
    }
    if(info.value.sc==0){
        alert('服务时长不能为空');
        return;
    }
    if(info.value.num.toString()=="asd"){
        alert('服务人数必须是整数');
        return;
    }
    if(info.value.sc.toString()=="asd"){
        alert('服务时长必须是整数');
        return;
    }
    axios.post("https://localhost:7041/api/kfzl/Addkfzl",info.value).then(res=>{
    if(res.data>0){
        alert('添加成功')
        router.push('kfshow');
    }
    else{
        alert('添加失败')
    }
})
}

</script>
